/**
 * @Title:  AttentionDynamicsActivity.java 
 * @Copyright:  XXX Co., Ltd. Copyright YYYY-YYYY,  All rights reserved 
 * @Description:  TODO<请描述此文件是做什么的> 
 * @author:  MeiYi 
 * @data:  2015-12-7 上午10:20:14 
 * @version:  V1.0 
 */

package artid.com.arttogoa.fragment;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import artid.com.arttogoa.R;
import artid.com.arttogoa.db.DataKeeper;
import artid.com.arttogoa.glide.GlideUtil;
import artid.com.arttogoa.parser.ArtworkImageUpload;
import artid.com.arttogoa.parser.MicMapBean;
import artid.com.arttogoa.parser.RecordDetailList;
import artid.com.arttogoa.task.CallbackSky;
import artid.com.arttogoa.util.VioceUtils;

/**
 * TODO<请描述这个类是干什么的>
 * 
 * @au thor 熊彬
 * @data: 2015-12-7 上午10:20:14
 * @version: V1.0
 */
public class GroupPhotoFragment extends Fragment implements OnClickListener {
	private TextView mTextView;
	private ImageView mImageView, vioce;
	private MicMapBean data;
	private CallbackSky call;
	private VioceUtils vu;
//	public boolean chenge = false;

	public GroupPhotoFragment(CallbackSky call) {
		this.call = call;
	}

	private RecordDetailList item;
	private EditText info;
	private String infoString;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater,
	 * android.view.ViewGroup, android.os.Bundle)
	 */
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View v = inflater.inflate(R.layout.fragment_group_photo, null);
		mTextView = (TextView) v.findViewById(R.id.tv_edit);
		mImageView = (ImageView) v.findViewById(R.id.iv_photo_graph);
		info = (EditText) v.findViewById(R.id.ed_info);
		mTextView.setOnClickListener(this);
		item = (RecordDetailList) DataKeeper.readSerializable(getActivity(),
				RecordDetailList.class);
		vioce = (ImageView) v.findViewById(R.id.iv_vioce);
		vu = new VioceUtils(getActivity(), vioce, info);
		vu.init();
		System.out.println(item.getPointinformation().get(1).getImgurl());
		setPhotoImage(item.getPointinformation().get(1).getImgurl());
		// mImageView.setImageBitmap(getLoacalBitmap(NetUtils.getLocalImage(item
		// .getPointinformation().get(0).getImgurl(), true)));
		infoString = item.getPointinformation().get(1).getText();
		info.setText(TextUtils.isEmpty(infoString) ? "" : infoString);
		// adapter = new AuctionAdapter(getActivity());
		// data = (MicMapBean) getArguments().getSerializable("data");
		// mImageView.setImageBitmap(getLoacalBitmap(data.getImage()));
		
		return v;
	}

	public ArtworkImageUpload getData() {
		if (!info.getText().toString().trim().equals(infoString))
			EditCache.gChenge = true;
		String infoString = info.getText().toString();
		ArtworkImageUpload artwork = new ArtworkImageUpload();
		if (TextUtils.isEmpty(infoString)) {
			Toast.makeText(getActivity(), "描述不能为空~", 2).show();
			return null;
		}
		artwork.setChenge(true);
		artwork.setGphoto_detail(infoString);
		return artwork;
	}
	
	public void setPhotoImage(String url) {
		GlideUtil.setImage(getActivity(), url, R.drawable.yspba_img_mor,
				R.drawable.yspba_img_mor, mImageView);
		// mImageView.setImageBitmap(getLoacalBitmap(url));
	}

	/**
	 * 加载本地图片 http://bbs.3gstdy.com
	 * 
	 * @param url
	 * @return
	 */
	public Bitmap getLoacalBitmap(String url) {
		try {
			FileInputStream fis = new FileInputStream(url);
			Bitmap bitmap = BitmapFactory.decodeStream(fis);
			return bitmap;
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			return null;
		}
	}
	

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.view.View.OnClickListener#onClick(android.view.View)
	 */
	@Override
	public void onClick(View view) {
		// TODO Auto-generated method stub
		switch (view.getId()) {
		case R.id.tv_edit:
			call.callBack(1);
			// call.callBack(data.getId());
			break;

		default:
			break;
		}
	}

}
